<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
JSJaC Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="JSJaCJID.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b>JSJaC</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>JSJaCJID.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		This file contains all things that make life easier when
 dealing with JIDs
 <BR/><BR/><B>Version: </B>$Revision: 437 $<BR/><BR/><B>Author:</B> Stefan Strigler
 <BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="JSJaCJID.html">JSJaCJID</a></b></td>
    <td>JSJaCJID models xmpp jid objects
 </td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="JSJaCJIDInvalidException.html">JSJaCJIDInvalidException</a></b></td>
    <td>Exception to indicate invalid values for a jid
 </td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/**
 * <span class="attrib">@fileoverview</span> This file contains all things that make life easier when
 * dealing with JIDs
 * <span class="attrib">@author</span> Stefan Strigler
 * <span class="attrib">@version</span> $Revision: 437 $
 */</span>

<span class="comment">/**
 * list of forbidden chars for nodenames
 * <span class="attrib">@private</span>
 */</span>
var JSJACJID_FORBIDDEN = [<span class="literal">'"'</span>,<span class="literal">' '</span>,<span class="literal">'&amp;'</span>,<span class="literal">'\'</span><span class="literal">','</span>/<span class="literal">','</span>:<span class="literal">','</span>&lt;<span class="literal">','</span>&gt;<span class="literal">','</span>@<span class="literal">'];

/**
 * Creates a new JSJaCJID object
 * @class JSJaCJID models xmpp jid objects
 * @constructor
 * @param {Object} jid jid may be either of type String or a JID represented
 * by JSON with fields '</span>node<span class="literal">', '</span>domain<span class="literal">' and '</span>resource<span class="literal">'
 * @throws JSJaCJIDInvalidException Thrown if jid is not valid
 * @return a new JSJaCJID object
 */
function JSJaCJID(jid) {
  /**
   *@private
   */
  this._node = '</span><span class="literal">';
  /**
   *@private
   */
  this._domain = '</span><span class="literal">';
  /**
   *@private
   */
  this._resource = '</span><span class="literal">';

  if (typeof(jid) == '</span>string<span class="literal">') {
    if (jid.indexOf('</span>@<span class="literal">') != -1) {
        this.setNode(jid.substring(0,jid.indexOf('</span>@<span class="literal">')));
        jid = jid.substring(jid.indexOf('</span>@<span class="literal">')+1);
    }
    if (jid.indexOf('</span>/<span class="literal">') != -1) {
      this.setResource(jid.substring(jid.indexOf('</span>/<span class="literal">')+1));
      jid = jid.substring(0,jid.indexOf('</span>/<span class="literal">'));
    }
    this.setDomain(jid);
  } else {
    this.setNode(jid.node);
    this.setDomain(jid.domain);
    this.setResource(jid.resource);
  }
}


/**
 * Gets the node part of the jid
 * @return A string representing the node name
 * @type String
 */
JSJaCJID.prototype.getNode = function() { return this._node; };

/**
 * Gets the domain part of the jid
 * @return A string representing the domain name
 * @type String
 */
JSJaCJID.prototype.getDomain = function() { return this._domain; };

/**
 * Gets the resource part of the jid
 * @return A string representing the resource
 * @type String
 */
JSJaCJID.prototype.getResource = function() { return this._resource; };


/**
 * Sets the node part of the jid
 * @param {String} node Name of the node
 * @throws JSJaCJIDInvalidException Thrown if node name contains invalid chars
 * @return This object
 * @type JSJaCJID
 */
JSJaCJID.prototype.setNode = function(node) {
  JSJaCJID._checkNodeName(node);
  this._node = node || '</span><span class="literal">';
  return this;
};

/**
 * Sets the domain part of the jid
 * @param {String} domain Name of the domain
 * @throws JSJaCJIDInvalidException Thrown if domain name contains invalid
 * chars or is empty
 * @return This object
 * @type JSJaCJID
 */
JSJaCJID.prototype.setDomain = function(domain) {
  if (!domain || domain == '</span><span class="literal">')
    throw new JSJaCJIDInvalidException("domain name missing");
  // chars forbidden for a node are not allowed in domain names
  // anyway, so let'</span>s check
  JSJaCJID._checkNodeName(domain);
  <span class="reserved">this</span>._domain = domain;
  <span class="reserved">return</span> <span class="reserved">this</span>;
};

<span class="comment">/**
 * Sets the resource part of the jid
 * <span class="attrib">@param</span> {String} resource Name of the resource
 * <span class="attrib">@return</span> This object
 * <span class="attrib">@type</span> JSJaCJID
 */</span>
JSJaCJID.<span class="reserved">prototype</span>.setResource = <span class="reserved">function</span>(resource) {
  <span class="reserved">this</span>._resource = resource || <span class="literal">''</span>;
  <span class="reserved">return</span> <span class="reserved">this</span>;
};

<span class="comment">/**
 * The string representation of the full jid
 * <span class="attrib">@return</span> A string representing the jid
 * <span class="attrib">@type</span> String
 */</span>
JSJaCJID.<span class="reserved">prototype</span>.toString = <span class="reserved">function</span>() {
  var jid = <span class="literal">''</span>;
  <span class="reserved">if</span> (<span class="reserved">this</span>.getNode() &amp;&amp; <span class="reserved">this</span>.getNode() != <span class="literal">''</span>)
    jid = <span class="reserved">this</span>.getNode() + <span class="literal">'@'</span>;
  jid += <span class="reserved">this</span>.getDomain(); <span class="comment">// we always have a domain</span>
  <span class="reserved">if</span> (<span class="reserved">this</span>.getResource() &amp;&amp; <span class="reserved">this</span>.getResource() != <span class="literal">""</span>)
    jid += <span class="literal">'/'</span> + <span class="reserved">this</span>.getResource();
  <span class="reserved">return</span> jid;
};

<span class="comment">/**
 * Removes the resource part of the jid
 * <span class="attrib">@return</span> This object
 * <span class="attrib">@type</span> JSJaCJID
 */</span>
JSJaCJID.<span class="reserved">prototype</span>.removeResource = <span class="reserved">function</span>() {
  <span class="reserved">return</span> <span class="reserved">this</span>.setResource();
};

<span class="comment">/**
 * creates a copy of this JSJaCJID object
 * <span class="attrib">@return</span> A copy of this
 * <span class="attrib">@type</span> JSJaCJID
 */</span>
JSJaCJID.<span class="reserved">prototype</span>.clone = <span class="reserved">function</span>() {
  <span class="reserved">return</span> new JSJaCJID(<span class="reserved">this</span>.toString());
};

<span class="comment">/**
 * Compares two jids if they belong to the same entity (i.e. w/o resource)
 * <span class="attrib">@param</span> {String} jid a jid as string or JSJaCJID object
 * <span class="attrib">@return</span> 'true' if jid is same entity as this
 * <span class="attrib">@type</span> Boolean
 */</span>
JSJaCJID.<span class="reserved">prototype</span>.isEntity = <span class="reserved">function</span>(jid) {
  <span class="reserved">if</span> (typeof jid == <span class="literal">'string'</span>)
	  jid = (new JSJaCJID(jid));
  jid.removeResource();
  <span class="reserved">return</span> (<span class="reserved">this</span>.clone().removeResource().toString() === jid.toString());
};

<span class="comment">/**
 * Check if node name is valid
 * <span class="attrib">@private</span>
 * <span class="attrib">@param</span> {String} node A name for a node
 * <span class="attrib">@throws</span> JSJaCJIDInvalidException Thrown if name for node is not allowed
 */</span>
JSJaCJID._checkNodeName = <span class="reserved">function</span>(nodeprep) {
    <span class="reserved">if</span> (!nodeprep || nodeprep == <span class="literal">''</span>)
      <span class="reserved">return</span>;
    <span class="reserved">for</span> (var i=0; i&lt; JSJACJID_FORBIDDEN.length; i++) {
      <span class="reserved">if</span> (nodeprep.indexOf(JSJACJID_FORBIDDEN[i]) != -1) {
        throw new JSJaCJIDInvalidException(<span class="literal">"forbidden char in nodename: "</span>+JSJACJID_FORBIDDEN[i]);
      }
    }
};

<span class="comment">/**
 * Creates a new Exception of type JSJaCJIDInvalidException
 * <span class="attrib">@class</span> Exception to indicate invalid values for a jid
 * <span class="attrib">@constructor</span>
 * <span class="attrib">@param</span> {String} message The message associated with this Exception
 */</span>
<span class="reserved">function</span> JSJaCJIDInvalidException(message) {
  <span class="comment">/**
   * The exceptions associated message
   * <span class="attrib">@type</span> String
   */</span>
  <span class="reserved">this</span>.message = message;
  <span class="comment">/**
   * The name of the exception
   * <span class="attrib">@type</span> String
   */</span>
  <span class="reserved">this</span>.name = <span class="literal">"JSJaCJIDInvalidException"</span>;
}
</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b>JSJaC</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Tue Feb 12 18:46:55 2008</div>
</body>
</html>
